home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / ms / s12349 / test_i.asm < prev    next >
Assembly Source File  |  1989-06-06  |  5KB  |  180 lines

  1.         PAGE    ,132
  2.         TITLE   Test Device Driver
  3.         SUBTTL  SAMPLE - Initialization routine
  4. .286P                   ; Enable 80286 protect-mode instructions
  5. ;============================================================================
  6. ;
  7. ; Register conventions:
  8. ;       DS:SI and SS:BP are set up by the strategy routine before dispatching
  9. ;       to the appropriate handler.
  10. ;
  11. ;       Each handler must preserve SS:BP and return control to an Exit label,
  12. ;       but may trash DS:SI, ES:DI, and even SP.  See SAMPExit for details.
  13. ;
  14. ;============================================================================
  15.  
  16.         INCLUDE SAMPDEFS.INC                    ; which includes some other .incs
  17.  
  18. STDOUT   EQU   1
  19.  
  20. HIGH_DATA       SEGMENT WORD PUBLIC 'FAR_DATA'
  21.  
  22. HIGH_DATA       ENDS
  23.  
  24.  
  25. HIGH_CODE       SEGMENT WORD PUBLIC 'FAR_CODE'
  26.  
  27. extrn     HighTimer:FAR
  28.  
  29. HIGH_CODE       ENDS
  30.  
  31.  
  32. MAIN_DATA SEGMENT WORD PUBLIC 'DATA'
  33. END_Of_DATA     LABEL   BYTE        ; Everything past here will be given
  34.                                     ; back to system at end of init
  35.  
  36. extrn  DevHlp:DWORD                 ; these variables are located in the data
  37.  
  38. SignonMsg     DB  13d, 10d, 'Example Multi-Segmented Device Driver',13d, 10d
  39. len           DW  $ - SignonMsg
  40.  
  41. MAIN_DATA       ENDS
  42.  
  43.  
  44. MAIN_CODE       SEGMENT WORD PUBLIC 'CODE'
  45.          ASSUME CS:MAIN_CODE,DS:MAIN_DATA,ES:NOTHING,SS:NOTHING
  46.  
  47. END_OF_CODE     LABEL   BYTE        ; Everything past here will be given
  48.                                     ; back to system at end of init
  49.  
  50.  
  51. ;============================================================================
  52. ;
  53. ; - SAMPINIT -
  54. ;
  55. ;       One time intialization code, called at system boot time.
  56. ;
  57. ; The Init routine will be called to set up the DevHlp address
  58. ; and do whatever hardware initialization is necessary.
  59. ;
  60. ;       Entry:  Local data contains the address of the command packet
  61. ;
  62. ;       Exit:   Return to the correct exit entry point based on whether
  63. ;               we were able to install or not.
  64. ;
  65.         PUBLIC  Do_Init
  66.  
  67. Do_Init PROC NEAR
  68.         ASSUME  DS:MAIN_DATA
  69. ;
  70. ; Output Sign-on Message
  71. ;
  72.  
  73. extrn   DOSPUTMESSAGE:FAR
  74. extrn   TimerHandler:FAR
  75. ;extrn   Handler:NEAR
  76. extrn   SAMPEXIT0:NEAR
  77.  
  78. ;
  79. ;
  80.         push    WORD PTR    STDOUT              ;File handle - standard output
  81.         push    len                             ;Length of message
  82.         push    ds                              ;Selector of message
  83.         push    OFFSET  SignonMsg               ;Address of message
  84.         call    DOSPUTMESSAGE                   ;AX destroyed
  85.  
  86. ; save DevHlp address in the variable DevHlp
  87.  
  88.         les     bx, [bp].LD_PTRSAVE             ; ES:BX -> request packet
  89.         mov     ax, word ptr es:[bx].InitDevHlp._off
  90.         mov     word ptr DevHlp._off, ax
  91.         mov     ax, word ptr es:[bx].InitDevHlp._seg
  92.         mov     word ptr DevHlp._seg, ax
  93. ;
  94. ; indicate the end of code and end of data segments in the request packet
  95.  
  96.         mov     ax,OFFSET MAIN_CODE:END_OF_CODE ; Set up end-of-code
  97.         mov     cx,OFFSET MAIN_DATA:END_Of_DATA ; and end of data
  98.  
  99.         mov     es:[bx].InitEcode,ax            ; save end marks in packet
  100.         mov     es:[bx].InitEdata,cx
  101.  
  102. ; lock the extra high data and code segments in the memory
  103.  
  104. IFDEF DEBUG
  105.         int     3
  106. ENDIF
  107.  
  108.         mov     ax, SEG HIGH_DATA
  109.         mov     bh, 01h                         ; long term lock
  110. ;       mov     bh, 03h                         ; long term lock
  111.         mov     bl, 0
  112.         DevHelp DevHlp_Lock
  113.         jnc     init1
  114.  
  115. IFDEF DEBUG
  116.         int     3
  117. ENDIF
  118.  
  119. init1:
  120.         mov     ax, SEG HIGH_CODE
  121.         mov     bh, 01h                         ; long term lock
  122. ;       mov     bh, 03h                         ; long term lock
  123.         mov     bl, 0
  124.         DevHelp DevHlp_Lock
  125.         jnc     init2
  126.  
  127. IFDEF DEBUG
  128.         int     3
  129. ENDIF
  130.  
  131. init2:
  132.         mov     ax, OFFSET MAIN_CODE:TimerHandler
  133.         mov     bx, 0FFFFh
  134.         DevHelp DevHlp_TickCount
  135.         jnc     fine
  136.  
  137. IFDEF DEBUG
  138.         int     3
  139. ENDIF
  140.  
  141. fine:
  142.  
  143. ;
  144. ; We are done with the INIT so exit.
  145. ;
  146.                                         ; Done, no error.
  147.         jmp     SAMPEXIT0               ; A routine in test.asm
  148.  
  149. ; ----------------------
  150. ;
  151. ; There's been an error.  Right now, the only possibility is that
  152. ; it's from DevHlp_GetDOSVar. In any case, we assume it serious enough that
  153. ; we can't install, so to tell OS/2 that we:
  154. ;
  155. ;   - set the number of units to 0
  156. ;   - set the ending code segment offset to 0
  157. ;   - set the ending data segment offset to 0
  158. ;   - set the error bit in the status word
  159. ;
  160. ; We jump to SAMPEXIT9, which sets the error bit in the status word.  I'm told
  161. ; that the actual error code doesn't matter, just the error bit; but "general
  162. ; failure" seems the closest, so what the heck.
  163. ;
  164. INIT_ERROR:
  165.  
  166.         LDS     BX,[BP].LD_PTRSAVE          ; DS:BX -> request block
  167.         XOR     AX,AX
  168.         MOV     [BX].INITCUNIT,AL          ; Set #units to 0.
  169.         MOV     [BX].InitEcode,AX
  170.         MOV     [BX].InitEdata,AX
  171. extrn      SAMPEXIT9:NEAR
  172.                                             ; Done, error = "general failure"
  173.  
  174.         JMP     SAMPEXIT9                   ; A routine in test.asm
  175.  
  176. Do_Init ENDP
  177.  
  178. MAIN_CODE       ENDS
  179.                 END
  180.